using System;
using System.Windows.Forms;
using System.Diagnostics;

using System.Collections;


namespace CUtil
{
	public enum ListViewYearEnum
	{
		Share,
		Quote,
		Year
	}
	/// <summary>
	/// Summary description for GridTrade.
	/// </summary>
	public class ListViewWithEnum :  System.Windows.Forms.ListView
	{
	
		
		protected ListViewSortManager listViewSortManager;
		ListViewSubItemColl listViewSubItemColl;
		object columnEnumeration;
		private int columnWidth = 80;

		//string[] currentListViewItem;

		public ListViewWithEnum():base()
		{
			this.View = System.Windows.Forms.View.Details;
			this.Dock = DockStyle.Fill;

			this.AllowColumnReorder = true;
			this.AllowDrop = true;
			this.FullRowSelect = true;
			this.GridLines = true;
			this.HideSelection = false;
			this.HoverSelection = true;

		}
		public ListViewWithEnum(object MyEnum):this()
		{
				Redraw(MyEnum);
	
		}
		public void Redraw(object MyEnum)
		{
			columnEnumeration = MyEnum;
			Redraw();
		}
		public void AddColumn(string str)
		{
			Columns.Add(str,columnWidth, System.Windows.Forms.HorizontalAlignment.Left);
			listViewSubItemColl[str] = string.Empty;

		}
		public void Redraw()
		{
			try
			{
				this.Columns.Clear();
				NewItem();
				for(int i = 0; i< listViewSubItemColl.Count; i++)
				{
					this.Columns.Add(listViewSubItemColl.Keys[i].ToString(),columnWidth, System.Windows.Forms.HorizontalAlignment.Left);

				}
			}
			catch
			{
				//this occurs in design mode - do nothing
			}
			
		}

		#region Properties Public
		
	



		#endregion

		public void NewItem()
		{
			listViewSubItemColl = new ListViewSubItemColl(columnEnumeration);
		}
		public void ClearSubItemCollection()
		{
			for(int i = 0; i < listViewSubItemColl.Count; i++)
			{
				listViewSubItemColl[i] = string.Empty;
			}
		}
		public void AddNewItem()
		{
			//listViewSubItemColl = new ListViewSubItemColl(MyEnum);

			string[] strArr = new string[listViewSubItemColl.Count];
			for(int i = 0; i < listViewSubItemColl.Count; i++)
			{
				strArr[i] = listViewSubItemColl[i].ToString();
			}

			ListViewItem lvi = new ListViewItem(strArr);
			this.Items.Add(lvi);
			lvi.EnsureVisible();
			System.Windows.Forms.Application.DoEvents();
		}
		public void ClearItems()
		{
			this.Items.Clear();
			for(int i = 0; i < listViewSubItemColl.Count; i++)
			{
				listViewSubItemColl[i] = string.Empty;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		public string this [int ind]   // indexer declaration
		{
			get 
			{
				return listViewSubItemColl[ind].ToString();
			}
			set 
			{
				listViewSubItemColl[ind] = (object)value;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		public string this [string name]   // indexer declaration
		{
			get 
			{
				return listViewSubItemColl[name].ToString();
			}
			set 
			{
				listViewSubItemColl[name] = (object)value;
			}
		}
		/// <summary>
		/// 
		/// </summary>
		public string this [object name]   // indexer declaration
		{
			get 
			{
				return listViewSubItemColl[name.ToString()].ToString();
			}
			set 
			{
				listViewSubItemColl[name.ToString()] = value;
			}
		}
	
	}
	/// <summary>
	/// Summary description for ListViewItemTrade.
	/// </summary>
	public class ListViewSubItemColl : CUtil.NameObjectCollection
	{

		public ListViewSubItemColl(object enumBase)
		{
		
			
			Enum u = enumBase as Enum;

			Type typ = enumBase.GetType();
			System.Array arr = Enum.GetValues(typ);
			
			for(int i = 0; i < arr.GetLength(0); i++)
			{
				string str = arr.GetValue(i).ToString();
				this.Add(str,string.Empty);
			}
			
		}
	}
	
}



